﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CSP.Receipts.DataModel;

namespace CSP.Receipts.Business
{
    public interface IUserRepository : CSP.EFPF.Common.IRepository<User, ReceiptContext>
    {
        bool ValidateUser(string username, string password);
    }

    public class UserManager : CSP.EFPF.CodeOnly.BaseRepository<User, ReceiptContext>, IUserRepository
    {
        /// <summary>
        /// Initializes a new instance of the UserManager class.
        /// </summary>
        public UserManager(CSP.EFPF.Common.IUnitOfWork<ReceiptContext> uow)
            : base(uow)
        {            
        }

        public bool ValidateUser(string username, string password)
        {
            return GetMany(user => user.Username == username && user.Password == password).Count() == 1;
        }
    }
}
